from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

option = Options()
option.add_experimental_option('detach', True)

#自动获取和当前浏览器匹配的webdriver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=option)

try:
    print("selenium 成功")

    driver.get('https://admin.java.crmeb.net/login')

    #账号
    userName = driver.find_element(By.XPATH,'//*[@id="app"]/div/div/div[2]/form/div[1]/div/div/input')
    userName.clear()
    userName.send_keys('demo')

    #密码
    pwd = driver.find_element(By.XPATH,'//*[@id="app"]/div/div/div[2]/form/div[2]/div/div/input')
    pwd.clear()
    pwd.send_keys('crmeb.com')

    #点击登录
    logon = driver.find_element(By.XPATH,'//*[@id="app"]/div/div/div[2]/form/div[3]/button')
    logon.click()

    #等待网页加载（防止网页超时）
    wait = WebDriverWait(driver,10)

    #获取用户访问量
    element = wait.until(EC.presence_of_element_located(
        (By.XPATH,'//*[@id="app"]/div/div[2]/section/div/div[1]/div/div[2]/div/div/div[2]/span')))
    print(element.text)

    svgElement = driver.find_element(By.XPATH,'//*[@id="hamburger-container"]')
    svgElement.click()

    #财务申请提现佣金
    element = driver.find_element(By.XPATH,
                                  '//*[@class="el-scrollbar"]/div/div/ul/div[9]')
    element.click()

    element = driver.find_element(By.XPATH,
                                  '//*[@class="el-scrollbar"]/div/div/ul/div[9]/li/ul/div[1]')
    element.click()

    element = driver.find_element(By.XPATH,
                                  '//*[@class="el-scrollbar"]/div/div/ul/div[9]/li/ul/div[1]/li/ul/div/a')
    element.click()
    wait = WebDriverWait(driver, 10)
    element = wait.until(EC.presence_of_element_located(
        (By.XPATH,'//*[@id="app"]/div/div[2]/section/div/div/div[2]/div/div[2]/div/div[2]/span[2]')))
    print(element.text)

    #获取cookie
    print(driver.get_cookies())

    #关闭窗口
    #driver.quit()
except Exception as e:
    print(f"Error occurred: {e}")